<?php
	require(__DATAGEN_CLASSES__ . '/TableProjectGen.class.php');

	/**
	 * The TableProject class defined here contains any
	 * customized code for the TableProject class in the
	 * Object Relational Model.  It represents the "table_project" table 
	 * in the database, and extends from the code generated abstract TableProjectGen
	 * class, which contains all the basic CRUD-type functionality as well as
	 * basic methods to handle relationships and index-based loading.
	 * 
	 * @package My Application
	 * @subpackage DataObjects
	 * 
	 */
	class TableProject extends TableProjectGen {
		/**
		 * Default "to string" handler
		 * Allows pages to _p()/echo()/print() this object, and to define the default
		 * way this object would be outputted.
		 *
		 * Can also be called directly via $objTableProject->__toString().
		 *
		 * @return string a nicely formatted string representation of this object
		 */
			protected $bid_id;
		public function __toString() {
			return sprintf('TableProject Object %s - %s',  $this->intId,  $this->intUserId);
		}

		
        //loaders
        public static function count_open_projects_all($objOptionalClauses = null) {

            $objDatabase = TableProject::GetDatabase();

            $strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project` AS `table_project` WHERE status=1 order by post_date';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            return $objResult[0];
            //return TableUserProjectTmp::InstantiateDbResult($objDbResult);
        }

        public static function load_open_projects_all_order_by_post_date($strParam1, $objOptionalClauses = null) {

            $objDatabase = TableProject::GetDatabase();

            $strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT `table_project`.* FROM `table_project` AS `table_project` WHERE status=1 order by post_date';

            $objDbResult = $objDatabase->Query($strQuery);
            //$objResult=$objDbResult->FetchArray();
            //return $objResult[0];
            return TableProject::InstantiateDbResult($objDbResult);
        }

        public static function count_open_projects_by_category_id($strParam1, $objOptionalClauses = null) {

            $objDatabase = TableProject::GetDatabase();

            $strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = sprintf('SELECT count(*) FROM `table_project` AS `table_project` WHERE category_id=%s and status=1 order by post_date',$strParam1);

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            return $objResult[0];
            //return TableUserProjectTmp::InstantiateDbResult($objDbResult);
        }

        public static function load_open_projects_by_category_id_order_by_post_date($strParam1, $objOptionalClauses = null) {

            $objDatabase = TableProject::GetDatabase();

            $strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = sprintf('SELECT `table_project`.* FROM `table_project` AS `table_project` WHERE category_id=%s and status=1 order by post_date',$strParam1);

            $objDbResult = $objDatabase->Query($strQuery);
            //$objResult=$objDbResult->FetchArray();
            //return $objResult[0];
            return TableProject::InstantiateDbResult($objDbResult);
        }

        //load TableProjectBid all: status=not inactive(1)
        public function load_bids_all_for_the_project_order_by_bid_date($objOptionalClauses = null) {

            $objDatabase = TableProjectBid::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

           $strQuery = sprintf('SELECT `table_project_bid`.* FROM `table_project_bid` AS `table_project_bid` WHERE project_id=%s and status!=1 order by bid_date',$this->Id);

            $objDbResult = $objDatabase->Query($strQuery);
            //$objResult=$objDbResult->FetchArray();
            //return $objResult[0];
            return TableProjectBid::InstantiateDbResult($objDbResult);
        }

        //will show all results for the request
        //only one or zero request will be active
        public function load_requests_cancel_all_for_the_project_order_by_request_date($objOptionalClauses = null) {

            $objDatabase = TableProjectBid::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = sprintf('SELECT `table_project_request_cancel`.* FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE project_id=%s and status!=0 order by request_date',$this->Id);

            $objDbResult = $objDatabase->Query($strQuery);
            //$objResult=$objDbResult->FetchArray();
            //return $objResult[0];
            return TableProjectRequestCancel::InstantiateDbResult($objDbResult);
        }

        //will show all results for the request
        //only one or zero  request will be active
        public function load_requests_complete_all_for_the_project_order_by_request_date($objOptionalClauses = null) {

            $objDatabase = TableProjectBid::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = sprintf('SELECT `table_project_request_complete`.* FROM `table_project_request_complete` AS `table_project_request_complete` WHERE project_id=%s order by request_date',$this->Id);

            $objDbResult = $objDatabase->Query($strQuery);
            //$objResult=$objDbResult->FetchArray();
            //return $objResult[0];
            return TableProjectRequestComplete::InstantiateDbResult($objDbResult);
        }

        //will show all results for the escrows
        public function load_escrows_all_for_the_project_order_by_escrow_date($objOptionalClauses = null) {

            $objDatabase = TableProjectBid::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = sprintf('SELECT `table_escrow`.* FROM `table_escrow` AS `table_escrow` WHERE project_id=%s order by escrow_date',$this->Id);

            $objDbResult = $objDatabase->Query($strQuery);
            //$objResult=$objDbResult->FetchArray();
            //return $objResult[0];
            return TableEscrow::InstantiateDbResult($objDbResult);
        }
      
        
	
        
       

        //properies
        //static     
        public static function bool_bidding_for_the_project($user_id_,$project_id_)
        {
            $objDatabase = TableProjectBid::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_bid` AS `table_project_bid` WHERE project_id='.$project_id_.' and user_id='.$user_id_;

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }

        public static function bool_can_manage_won_for_the_project($provider_id_,$project_id_)
        {
            $objDatabase = TableProjectWon::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            //status not retracted
            $strQuery = 'SELECT count(*) FROM `table_project_won` AS `table_project_won` WHERE project_id='.$project_id_.' and provider_id='.$provider_id_.' and status!=1';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }

        public static function bool_can_pick_for_the_project($buyer_id_,$project_id_)
        {
            $objDatabase = TableProjectWon::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            //status not retracted
            $strQuery = 'SELECT count(*) FROM `table_project_won` AS `table_project_won` WHERE project_id='.$project_id_.' and buyer_id='.$buyer_id_.' and status!=1';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]==0)return true;

            return false;
        }

        public static function bool_done_pick_for_the_project($buyer_id_,$project_id_)
        {
            $objDatabase = TableProjectWon::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            //status not retracted
            $strQuery = 'SELECT count(*) FROM `table_project_won` AS `table_project_won` WHERE project_id='.$project_id_.' and buyer_id='.$buyer_id_.' and status!=1';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }

        public static function bool_can_accept_won_for_the_project($provider_id_,$project_id_)
        {
            $objDatabase = TableProjectWon::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            //status not retracted
            $strQuery = 'SELECT count(*) FROM `table_project_won` AS `table_project_won` WHERE project_id='.$project_id_.' and provider_id='.$provider_id_.' and status=0';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]==0)return true;

            return false;
        }

        public static function bool_done_accept_won_for_the_project($provider_id_,$project_id_)
        {
            $objDatabase = TableProjectWon::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            //status not retracted
            $strQuery = 'SELECT count(*) FROM `table_project_won` AS `table_project_won` WHERE project_id='.$project_id_.' and provider_id='.$provider_id_.' and status>1';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }
        
         public static function bool_won_for_the_project($provider_id_,$project_id_)
        {
            $objDatabase = TableProjectWon::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            //status not retracted
            $strQuery = 'SELECT count(*) FROM `table_project_won` AS `table_project_won` WHERE project_id='.$project_id_.' and provider_id='.$provider_id_.' and status>1';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }

        public static function bool_done_retract_won_for_the_project($provider_id_,$project_id_)
        {
            $objDatabase = TableProjectWon::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            //status not retracted
            $strQuery = 'SELECT count(*) FROM `table_project_won` AS `table_project_won` WHERE project_id='.$project_id_.' and provider_id='.$provider_id_.' and status=1';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }

        //request
        public static function bool_requesting_cancel_for_the_project($buyer_id_,$project_id_)
        {
            $objDatabase = TableProjectRequestCancel::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE project_id='.$project_id_.' and buyer_id='.$buyer_id_.' and status=0';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }

        public static function bool_requested_cancel_for_the_project($provider_id_,$project_id_)
        {
            $objDatabase = TableProjectRequestCancel::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE project_id='.$project_id_.' and provider_id='.$provider_id_.' and status=0';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }

        public static function bool_requesting_complete_for_the_project($provider_id_,$project_id_)
        {
            $objDatabase = TableProjectRequestComplete::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_request_complete` AS `table_project_request_complete` WHERE project_id='.$project_id_.' and provider_id='.$provider_id_.' and status=0';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }

        public static function bool_requested_complete_for_the_project($buyer_id_,$project_id_)
        {
            $objDatabase = TableProjectRequestComplete::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_request_complete` AS `table_project_request_complete` WHERE project_id='.$project_id_.' and buyer_id='.$buyer_id_.' and status=0';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }
            public static function bool_already_project_accept($project_id_,$buyer_id_,$provider_id_)
        {
            $objDatabase = TableProjectWon::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

        $strQuery = 'SELECT id FROM `table_project_won` AS `table_project_won` WHERE project_id='.$project_id_.' and buyer_id='.$buyer_id_.' and provider_id='.$provider_id_.' and status=2';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            if($objResult[0]>0)return true;

            return false;
        }

        //request mismatched(decliendand denied the request)
        public static function count_declined_request_cancel_for_the_project($project_id_)
        {
            $objDatabase = TableProjectRequestCancel::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE project_id='.$project_id_.' and status=2';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            return $objResult[0];
        }

        public static function count_declined_request_complete_for_the_project($project_id_)
        {
            $objDatabase = TableProjectRequestComplete::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE project_id='.$project_id_.' and status=2';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            return $objResult[0];
        }
        //request accepted
        public static function count_accepted_request_cancel_for_the_project($project_id_)
        {
            $objDatabase = TableProjectRequestCancel::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE project_id='.$project_id_.' and status=3';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            return $objResult[0];
        }

        public static function count_accepted_request_complete_for_the_project($project_id_)
        {
            $objDatabase = TableProjectRequestComplete::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_request_cancel` AS `table_project_request_cancel` WHERE project_id='.$project_id_.' and status=3';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            return $objResult[0];
        }
        
        //review

        //message
        public static function count_unread_private_message_for_the_project($user_id_,$project_id_)
        {
            $objDatabase = TablePrivateMessage::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_private_message` AS `table_private_message` WHERE project_id='.$project_id_.' and user_id_to='.$user_id_.' and message_opened=\'n\'';

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            return $objResult[0];
        }

        public static function count_bid_for_the_project($project_id_)
        {
            $objDatabase = TableProjectBid::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_bid` AS `table_project_bid` WHERE project_id='.$project_id_;

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();
            
            return $objResult[0];
        }

        //for the instance
        public function count_bid_for_this_project()
        {
            $objDatabase = TableProjectBid::GetDatabase();

            //$strParam1 = $objDatabase->SqlVariable($strParam1);

            $strQuery = 'SELECT count(*) FROM `table_project_bid` AS `table_project_bid` WHERE project_id='.$this->Id;

            //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

            $objDbResult = $objDatabase->Query($strQuery);
            $objResult=$objDbResult->FetchArray();

            return $objResult[0];
        }


        //
        public function bool_my_project($key_)
        {
            if($this->UserId==$key_)
            {
                return true;
            }
            return false;
        }

        public function bool_won_project($key_)
        {
            if($this->WonUserId==$key_)
            {
                return true;
            }
            return false;
        }

        public function bool_open_project()
        {
            if($this->Status==0 || $this->Status==1 || $this->Status==2)
            {
                return true;
            }
            return false;
        }

        public function bool_after_bid_project()
        {
            if($this->Status==2)
            {
                return true;
            }
            return false;
        }

        public function bool_after_picked_project()
        {
            if($this->Status==3)
            {
                return true;
            }
            return false;
        }

        public function bool_starting_project()
        {
            if($this->Status==4 || $this->Status==5)
            {
                return true;
            }
            return false;
        }

        public function bool_canceled_project()
        {
            if($this->Status==6 || $this->Status==7)
            {
                return true;
            }
            return false;
        }

        public function bool_canceled_and_reviewed_project()
        {
            if($this->Status==7)
            {
                return true;
            }
            return false;
        }

        public function bool_completed_project()
        {
            if($this->Status==8)
            {
                return true;
            }
            return false;
        }

        public function bool_completed_and_reviewed_project()
        {
            if($this->Status==9)
            {
                return true;
            }
            return false;
        }

        public function bool_failed_project()
        {
            if($this->Status==10)
            {
                return true;
            }
            return false;
        }

        public function bool_failed_and_reviewed_project()
        {
            if($this->Status==11)
            {
                return true;
            }
            return false;
        }

        public function bool_expired_project()
        {
            if($this->Status==12 || $this->Status==13 || $this->Status==14 || $this->Status==15)
            {
                return true;
            }
            return false;
        }

        public function bool_canceled_and_expired_project()
        {
            if($this->Status==12)
            {
                return true;
            }
            return false;
        }

        public function bool_completed_and_expired_project()
        {
            if($this->Status==13)
            {
                return true;
            }
            return false;
        }

        public function bool_failed_and_expired_project()
        {
            if($this->Status==14)
            {
                return true;
            }
            return false;
        }

        public function bool_no_winner_and_expired_project()
        {
            if($this->Status==15)
            {
                return true;
            }
            return false;
        }

        //review can be done if the project is completed.
        //completed status will be set after provider request the completion and accepted by buyer.
        //if the project is completed with agreement,both users can rate and review each other for free of charge.
        public function bool_can_review_for_free()
        {
            if(bool_completed_project() || bool_completed_and_reviewed_project())
            {
                return true;
            }
            return false;
        }

        public function bool_can_review_with_fees()
        {
            if(bool_failed_project() || bool_failed_and_reviewed_project())
            {
                return true;
            }
            return false;
        }
        
        //get
        // + href
        public function get_textlink_for_buyer()
        {
            //if(is_null($this->User))return 'null?'.$this->UserId;
            if(is_null($this->User))return '';

            return '<a href="/user.php?id='.$this->UserId.'">'.$this->User->UserName.'</a>';
        }

        public function get_textlink_for_provider()
        {
            //if(is_null($this->WonUser))return 'null?'.$this->WonUserId;
            if(is_null($this->WonUser))return '';

            return '<a href="/user.php?id='.$this->WonUserId.'">'.$this->WonUser->UserName.'</a>';
        }
        //text + href popup (target="blank" will be used for now)
        public function get_textlink_for_project_message_popup()
        {
            return '<a target="blank" href="'.$this->get_href_for_project_message_popup().'">'.'[view project board]'.'</a>';
        }

        public function get_textlink_to_bid_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_bid_popup().'">'.'[bid this project]'.'</a>';
        }

        public function get_textlink_to_select_bid_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_select_bid_popup().'">'.'[select provider]'.'</a>';
        }

        public function get_textlink_to_select_bid_with_the_provider_popup($provider_id_)
        {
            return '<a target="blank" href="'.$this->get_href_to_select_bid_with_the_provider_popup($provider_id_).'">'.'[award this provider]'.'</a>';
        }

        public function get_textlink_to_cancel_bid_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_cancel_bid_popup().'">'.'[cancel bid]'.'</a>';
        }

        public function get_textlink_to_edit_bid_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_edit_bid_popup().'">'.'[edit bid]'.'</a>';
        }

        public function get_textlink_to_manage_won_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_manage_won_popup().'">'.'[manege won]'.'</a>';
        }

        public function get_textlink_to_request_cancel_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_request_cancel_popup().'">'.'[request cancel]'.'</a>';
        }

        public function get_textlink_to_request_complete_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_request_complete_popup().'">'.'[request complete]'.'</a>';
        }

        public function get_textlink_to_accept_cancel_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_accept_cancel_popup().'">'.'[accept cancel request]'.'</a>';
        }

        public function get_textlink_to_accept_complete_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_accept_complete_popup().'">'.'[accept complete request]'.'</a>';
        }

        public function get_textlink_to_decline_cancel_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_decline_cancel_popup().'">'.'[decline cancel request]'.'</a>';
        }
        

        public function get_textlink_to_decline_complete_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_decline_complete_popup().'">'.'[decline complete request]'.'</a>';
        }

        //for retracting the cancel request
        public function get_textlink_to_retract_cancel_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_retract_cancel_popup().'">'.'[retract cancel request]'.'</a>';
        }
        //for retracting the complete request
        public function get_textlink_to_retract_complete_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_retract_complete_popup().'">'.'[retract complete request]'.'</a>';
        }

        public function get_textlink_to_new_review_popup()
        {
            return '<a target="blank" href="'.$this->get_href_for_new_review_popup().'">'.'[new review]'.'</a>';
        }

        //the_user will always be a provider. because buyer's id can be found by the project.
        public function get_textlink_to_show_private_message_with_the_user_popup($user_id_)
        {
            return '<a target="blank" href="'.$this->get_href_to_show_private_message_with_the_user_popup().'">'.'[PM]'.'</a>';
        }
        //
          public function get_textlink_to_retract_bid_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_retract_bid_popup().'">'.'Retract Bid&nbsp;&nbsp;'.'<img src="media/popup_small.gif" alt="" border="0" align="absmiddle" /></a>';
        }
          public function get_textlink_to_accept_won_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_accept_won_popup().'">'.'Accept Won&nbsp;&nbsp;'.'<img src="media/popup_small.gif" alt="" border="0" align="absmiddle" /></a>';
        }
          public function get_textlink_to_retract_won_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_retract_won_popup().'">'.'Retract Won&nbsp;&nbsp;'.'<img src="media/popup_small.gif" alt="" border="0" align="absmiddle" /></a><span class="rowBreak_3_"></span>';
        }
          public function get_textlink_to_bookmark_project_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_bookmark_project_popup().'">'.'Bookmark this Project&nbsp;&nbsp;'.'<img src="media/popup_small.gif" alt="" border="0" align="absmiddle" /></a><span class="rowBreak_3_"></span>';
        }
          public function get_textlink_to_report_violation_popup()
        {
            return '<a target="blank" href="'.$this->get_href_to_report_violation_popup().'">'.'Report Violation&nbsp;&nbsp;'.'<img src="media/popup_small.gif" alt="" border="0" align="absmiddle" /></a>';
        }


        //only href
        public function get_href_for_project_message_popup()
        {
            return '/popup_project_message.php?id='.$this->Id;
        }

        public function get_href_to_bid_popup()
        {
            return '/popup_bid.php?id='.$this->Id;
        }

        public function get_href_to_select_bid_popup()
        {
            return '/popup_select_bid.php?id='.$this->Id;
        }

        public function get_href_to_select_bid_with_the_provider_popup($provider_id_)
        {
            return '/popup_select_bid.php?id='.$this->Id.'&uid='.$provider_id_;
        }

        public function get_href_to_cancel_bid_popup()
        {	
        
        	
            return '/popup_cancel_bid.php?id='.$this->Id;
        }

        public function get_href_to_edit_bid_popup()
        {
            return '/popup_edit_bid.php?id='.$this->Id;
        }

        public function get_href_to_manage_won_popup()
        {
            return '/popup_manage_won.php?id='.$this->Id;
        }

        public function get_href_to_request_cancel_popup()
        {
            return '/popup_request_cancel.php?id='.$this->Id;
        }

        public function get_href_to_request_complete_popup()
        {
            return '/popup_request_complete.php?id='.$this->Id;
        }

        public function get_href_to_accept_cancel_popup()
        {
            return '/popup_accept_cancel.php?id='.$this->Id;
        }

        public function get_href_to_accept_complete_popup()
        {
            return '/popup_accept_complete.php?id='.$this->Id;
        }

        public function get_href_to_decline_cancel_popup()
        {
            return '/popup_decline_cancel.php?id='.$this->Id;
        }

        public function get_href_to_decline_complete_popup()
        {
            return '/popup_decline_complete.php?id='.$this->Id;
        }

        //for retracting the cancel request
        public function get_href_to_retract_cancel_popup()
        {
            return '/popup_retract_cancel.php?id='.$this->Id;
        }
        //for retracting the complete request
        public function get_href_to_retract_complete_popup()
        {
            return '/popup_retract_complete.php?id='.$this->Id;
        }

        public function get_href_for_new_review_popup()
        {
            return '/popup_new_review.php?id='.$this->Id;
        }
        //// 
        public function get_href_to_retract_bid_popup()
        {
            return '/popup_retract_bid.php?id='.$this->Id;
        }
         public function get_href_to_accept_won_popup()
        {
            return '/popup_accept_won.php?id='.$this->Id;
        }
         public function get_href_to_retract_won_popup()
        {
            return '/popup_retract_won.php?id='.$this->Id;
        }
         public function get_href_to_bookmark_project_popup()
        {
            return '/popup_bookmark_project.php?id='.$this->Id;
        }
         public function get_href_to_report_violation_popup()
        {
            return '/popup_report_violate.php?id='.$this->Id;
        }

        //the_user will always be a provider. because buyer's id can be found by the project.
        public function get_href_to_show_private_message_with_the_user_popup($user_id_)
        {
            return '/popup_private_message.php?id='.$this->Id.'&uid='.$user_id_;
        }

        //properties
        public function get_html_status()
        {
            //if(is_null($this->User))return 'null?'.$this->UserId;
            if($this->bool_open_project())return '<div class="green">Open</div>';
            if($this->bool_starting_project())return 'Starting';
            if($this->bool_canceled_project())return 'Cancelled';
            if($this->bool_completed_project())return 'Completed';
            if($this->bool_failed_project())return 'Failed';
            if($this->bool_canceled_and_expired_project())return 'Cancelled';
            if($this->bool_completed_and_expired_project())return 'Completed';
            if($this->bool_failed_and_expired_project())return 'Failed';
            if($this->bool_no_winner_and_expired_project())return 'Timeout';

            return '';
        }

        public function get_html_budget()
        {
            return ''.$this->BudgetExact;

            //return '<a href="/user.php?id='.$this->WonUserId.'">'.$this->WonUser->UserName.'</a>';
        }

        public function get_html_category()
        {
            if($this->CategoryId==0)return QApplication::Translate('Design > Web');
            if($this->CategoryId==1)return QApplication::Translate('Design > Web');
            if($this->CategoryId==2)return QApplication::Translate('Design > Web');
            if($this->CategoryId==3)return QApplication::Translate('Design > Web');
            if($this->CategoryId==4)return QApplication::Translate('Design > Web');
            if($this->CategoryId==5)return QApplication::Translate('Design > Web');
            if($this->CategoryId==6)return QApplication::Translate('Design > Web');
            if($this->CategoryId==7)return QApplication::Translate('Design > Web');
            if($this->CategoryId==8)return QApplication::Translate('Design > Web');
            if($this->CategoryId==9)return QApplication::Translate('Design > Web');
            if($this->CategoryId==10)return QApplication::Translate('Design > Web');
            if($this->CategoryId==11)return QApplication::Translate('Design > Web');
            if($this->CategoryId==12)return QApplication::Translate('Design > Web');
            if($this->CategoryId==13)return QApplication::Translate('Design > Web');
            if($this->CategoryId==14)return QApplication::Translate('Design > Web');
            if($this->CategoryId==15)return QApplication::Translate('Design > Web');
            if($this->CategoryId==16)return QApplication::Translate('Design > Web');
            if($this->CategoryId==17)return QApplication::Translate('Design > Web');
            if($this->CategoryId==18)return QApplication::Translate('Design > Web');
            if($this->CategoryId==19)return QApplication::Translate('Design > Web');
            if($this->CategoryId==20)return QApplication::Translate('Design > Web');
            if($this->CategoryId==21)return QApplication::Translate('Design > Web');
            if($this->CategoryId==22)return QApplication::Translate('Design > Web');
            if($this->CategoryId==23)return QApplication::Translate('Design > Web');
            if($this->CategoryId==24)return QApplication::Translate('Design > Web');
            if($this->CategoryId==25)return QApplication::Translate('Design > Web');
            if($this->CategoryId==26)return QApplication::Translate('Design > Web');
            if($this->CategoryId==27)return QApplication::Translate('Design > Web');
            if($this->CategoryId==28)return QApplication::Translate('Design > Web');
            if($this->CategoryId==29)return QApplication::Translate('Design > Web');
            if($this->CategoryId==30)return QApplication::Translate('Design > Web');
            if($this->CategoryId==31)return QApplication::Translate('Design > Web');
            if($this->CategoryId==32)return QApplication::Translate('Design > Web');
            if($this->CategoryId==33)return QApplication::Translate('Design > Web');
            if($this->CategoryId==34)return QApplication::Translate('Design > Web');
            if($this->CategoryId==35)return QApplication::Translate('Design > Web');
            if($this->CategoryId==36)return QApplication::Translate('Design > Web');
            if($this->CategoryId==37)return QApplication::Translate('Design > Web');
            if($this->CategoryId==38)return QApplication::Translate('Design > Web');
            if($this->CategoryId==39)return QApplication::Translate('Design > Web');
            if($this->CategoryId==40)return QApplication::Translate('Design > Web');
            if($this->CategoryId==41)return QApplication::Translate('Design > Web');
            if($this->CategoryId==42)return QApplication::Translate('Design > Web');
            if($this->CategoryId==43)return QApplication::Translate('Design > Web');
            if($this->CategoryId==44)return QApplication::Translate('Design > Web');
            if($this->CategoryId==45)return QApplication::Translate('Design > Web');
            if($this->CategoryId==46)return QApplication::Translate('Design > Web');
            if($this->CategoryId==47)return QApplication::Translate('Design > Web');
            if($this->CategoryId==48)return QApplication::Translate('Design > Web');
            if($this->CategoryId==49)return QApplication::Translate('Design > Web');
            if($this->CategoryId==50)return QApplication::Translate('Design > Web');
            if($this->CategoryId==51)return QApplication::Translate('Design > Web');
            if($this->CategoryId==52)return QApplication::Translate('Design > Web');
            if($this->CategoryId==53)return QApplication::Translate('Design > Web');
            if($this->CategoryId==54)return QApplication::Translate('Design > Web');
            if($this->CategoryId==55)return QApplication::Translate('Design > Web');
            if($this->CategoryId==56)return QApplication::Translate('Design > Web');
            if($this->CategoryId==57)return QApplication::Translate('Design > Web');
            if($this->CategoryId==58)return QApplication::Translate('Design > Web');
            if($this->CategoryId==59)return QApplication::Translate('Design > Web');
            if($this->CategoryId==60)return QApplication::Translate('Design > Web');
            if($this->CategoryId==61)return QApplication::Translate('Design > Web');
            if($this->CategoryId==62)return QApplication::Translate('Design > Web');
            if($this->CategoryId==63)return QApplication::Translate('Design > Web');
            if($this->CategoryId==64)return QApplication::Translate('Design > Web');
            if($this->CategoryId==65)return QApplication::Translate('Design > Web');
            if($this->CategoryId==66)return QApplication::Translate('Design > Web');
            if($this->CategoryId==67)return QApplication::Translate('Design > Web');
            if($this->CategoryId==78)return QApplication::Translate('Design > Web');
            if($this->CategoryId==79)return QApplication::Translate('Design > Web');
            if($this->CategoryId==80)return QApplication::Translate('Design > Web');
            if($this->CategoryId==81)return QApplication::Translate('Design > Web');
            if($this->CategoryId==82)return QApplication::Translate('Design > Web');
            if($this->CategoryId==83)return QApplication::Translate('Design > Web');
            if($this->CategoryId==84)return QApplication::Translate('Design > Web');
            if($this->CategoryId==85)return QApplication::Translate('Design > Web');
            if($this->CategoryId==86)return QApplication::Translate('Design > Web');
            if($this->CategoryId==87)return QApplication::Translate('Design > Web');
            if($this->CategoryId==88)return QApplication::Translate('Design > Web');
            if($this->CategoryId==89)return QApplication::Translate('Design > Web');
            if($this->CategoryId==90)return QApplication::Translate('Design > Web');
            if($this->CategoryId==91)return QApplication::Translate('Design > Web');
            if($this->CategoryId==92)return QApplication::Translate('Design > Web');
            if($this->CategoryId==93)return QApplication::Translate('Design > Web');
            if($this->CategoryId==94)return QApplication::Translate('Design > Web');
            if($this->CategoryId==95)return QApplication::Translate('Design > Web');
            if($this->CategoryId==96)return QApplication::Translate('Design > Web');
            if($this->CategoryId==97)return QApplication::Translate('Design > Web');
            if($this->CategoryId==98)return QApplication::Translate('Design > Web');
            if($this->CategoryId==99)return QApplication::Translate('Design > Web');
            if($this->CategoryId==100)return QApplication::Translate('Design > Web');
        }

        public function get_html_post_date()
        {
            return ''.$this->PostDate;

            //return '<a href="/user.php?id='.$this->WonUserId.'">'.$this->WonUser->UserName.'</a>';
        }

        public function get_html_time_limit_date()
        {
            return ''.$this->TimeLimitDate;

            //return '<a href="/user.php?id='.$this->WonUserId.'">'.$this->WonUser->UserName.'</a>';
        }

        public function get_html_bid_count()
        {
            return ''.$this->TotalBid;

            //return '<a href="/user.php?id='.$this->WonUserId.'">'.$this->WonUser->UserName.'</a>';
        }

        public function get_html_avg_bid()
        {
            return ''.$this->AverageBid;

            //return '<a href="/user.php?id='.$this->WonUserId.'">'.$this->WonUser->UserName.'</a>';
        }

        public function get_html_page_view()
        {
            return ''.$this->PageView;

            //return '<a href="/user.php?id='.$this->WonUserId.'">'.$this->WonUser->UserName.'</a>';
        }

        public function get_html_deadline_date()
        {
            return ''.$this->DeadlineDate;

            //return '<a href="/user.php?id='.$this->WonUserId.'">'.$this->WonUser->UserName.'</a>';
        }

        public function get_html_project_board_message_count()
        {
            return 0;

            //return '<a href="/user.php?id='.$this->WonUserId.'">'.$this->WonUser->UserName.'</a>';
        }



        //set
        public function set_status_init()
        {
            $this->Status=0;
        }

        public function set_status_open()
        {
            $this->Status=1;
        }

        public function set_status_after_bid_project()
        {
            $this->Status=2;
        }

        public function set_status_after_picked_project()
        {
            $this->Status=3;
        }

        public function set_status_accept_and_starting_project()
        {
            $this->Status=4;
        }

        public function set_status_canceled()
        {
            $this->Status=6;
        }

        public function set_status_canceled_and_reviewed_project()
        {
            $this->Status=7;
        }

        public function set_status_completed_project()
        {
            $this->Status=8;
        }

        public function set_status_completed_and_reviewed_project()
        {
            $this->Status=9;
        }

        public function set_status_failed_project()
        {
            $this->Status=10;
        }

        public function set_status_failed_and_reviewed_project()
        {
            $this->Status=11;
        }

        public function set_status_canceled_and_expired_project()
        {
            $this->Status=12;
        }

        public function set_status_completed_and_expired_project()
        {
            $this->Status=13;
        }

        public function set_status_failed_and_expired_project()
        {
            $this->Status=14;
        }

        public function set_status_no_winner_and_expired_project()
        {
            $this->Status=15;
        }
		  public function set_status_request_for_cancel()
        {
             $this->Status=16;
        }

          public function set_status_request_to_complete_project()
        {
            $this->Status=17;
        }

        //functions
        public function set_post_date_for_now()
        {
            $this->PostDate=QDateTime::Now();
        }

        public function set_close_date_for_now()
        {
            $this->CloseDate=QDateTime::Now();
        }

        public function set_cancel_date_for_now()
        {
            $this->CancelDate=QDateTime::Now();
        }

        public function set_end_date_for_now()
        {
            $this->EndDate=QDateTime::Now();
        }

        public function set_won_date_for_now()
        {
            $this->WonDate=QDateTime::Now();
        }

        public function set_start_date_for_now()
        {
            $this->StartDate=QDateTime::Now();
        }
        
       

		// Override or Create New Load/Count methods
		// (For obvious reasons, these methods are commented out...
		// but feel free to use these as a starting point)
/*
		public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses = null) {
			// This will return an array of TableProject objects
			return TableProject::QueryArray(
				QQ::AndCondition(
					QQ::Equal(QQN::TableProject()->Param1, $strParam1),
					QQ::GreaterThan(QQN::TableProject()->Param2, $intParam2)
				),
				$objOptionalClauses
			);
		}

		public static function LoadBySample($strParam1, $intParam2, $objOptionalClauses = null) {
			// This will return a single TableProject object
			return TableProject::QuerySingle(
				QQ::AndCondition(
					QQ::Equal(QQN::TableProject()->Param1, $strParam1),
					QQ::GreaterThan(QQN::TableProject()->Param2, $intParam2)
				),
				$objOptionalClauses
			);
		}

		public static function CountBySample($strParam1, $intParam2, $objOptionalClauses = null) {
			// This will return a count of TableProject objects
			return TableProject::QueryCount(
				QQ::AndCondition(
					QQ::Equal(QQN::TableProject()->Param1, $strParam1),
					QQ::Equal(QQN::TableProject()->Param2, $intParam2)
				),
				$objOptionalClauses
			);
		}

		public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses) {
			// Performing the load manually (instead of using QCubed Query)

			// Get the Database Object for this Class
			$objDatabase = TableProject::GetDatabase();

			// Properly Escape All Input Parameters using Database->SqlVariable()
			$strParam1 = $objDatabase->SqlVariable($strParam1);
			$intParam2 = $objDatabase->SqlVariable($intParam2);

			// Setup the SQL Query
			$strQuery = sprintf('
				SELECT
					`table_project`.*
				FROM
					`table_project` AS `table_project`
				WHERE
					param_1 = %s AND
					param_2 < %s',
				$strParam1, $intParam2);

			// Perform the Query and Instantiate the Result
			$objDbResult = $objDatabase->Query($strQuery);
			return TableProject::InstantiateDbResult($objDbResult);
		}
*/




		// Override or Create New Properties and Variables
		// For performance reasons, these variables and __set and __get override methods
		// are commented out.  But if you wish to implement or override any
		// of the data generated properties, please feel free to uncomment them.
/*
		protected $strSomeNewProperty;

		public function __get($strName) {
			switch ($strName) {
				case 'SomeNewProperty': return $this->strSomeNewProperty;

				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		public function __set($strName, $mixValue) {
			switch ($strName) {
				case 'SomeNewProperty':
					try {
						return ($this->strSomeNewProperty = QType::Cast($mixValue, QType::String));
					} catch (QInvalidCastException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				default:
					try {
						return (parent::__set($strName, $mixValue));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}
*/
	}
?>